package stark.app.function.signtool;

import android.graphics.Color;

import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.stark.sign.tool.bean.ColorBean;

import org.jetbrains.annotations.NotNull;

import stark.app.R;
import stark.app.databinding.ItemSignColorBinding;
import stark.common.basic.adapter.BaseDBRVAdapter;

/**
 * Author：daizhongbin on 2021/9/23
 * Email：1027154338@qq.com
 * Desc:
 */
public class SignColorAdapter extends BaseDBRVAdapter<ColorBean, ItemSignColorBinding> {

    private int selPos = -1;

    public SignColorAdapter() {
        super(R.layout.item_sign_color, 0);
    }

    @Override
    public void onBindViewHolder(@NotNull BaseDataBindingHolder<ItemSignColorBinding> holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.getDataBinding().tvName.setSelected(selPos == position);
    }

    @Override
    protected void convert(@NotNull BaseDataBindingHolder<ItemSignColorBinding> holder, ColorBean colorBean) {
        super.convert(holder, colorBean);
        ItemSignColorBinding binding = holder.getDataBinding();
        binding.ivImg.setBackgroundColor(Color.parseColor(colorBean.getValue()));
        binding.tvName.setText(colorBean.getName());
    }

    public void setSelPos(int selPos) {
        if (this.selPos == selPos) {
            return;
        }
        this.selPos = selPos;
        notifyDataSetChanged();
    }

    public ColorBean getSelColor() {
        if (selPos < 0) {
            return null;
        }
        return getItem(selPos);
    }
}
